﻿//4. Write a program, that reads from the console an array of N integers and an integer K,
//sorts the array and using the method Array.BinSearch() finds the largest number in the array which is ≤ K.


using System;
using System.Collections.Generic;

class LargestNumberUnderK
{
    static void Main()
    {
        int numberN = int.Parse(Console.ReadLine());
        int[] arrnumberN = new int[numberN];
        for (int i = 0; i < arrnumberN.Length; i++)
        {
            arrnumberN[i] = int.Parse(Console.ReadLine());
        }
        int numberK = int.Parse(Console.ReadLine());
        Array.Sort(arrnumberN);
        foreach (var e in arrnumberN)
        {
            Console.Write("{0} ", e);
        }
        Console.WriteLine();
        int searchNumberKOrLess = Array.BinarySearch(arrnumberN, numberK);
        Console.WriteLine(searchNumberKOrLess);
        if (searchNumberKOrLess >= 0)
        {
            Console.WriteLine("Largest number is {0} equal to number K", numberK);
        }
        else if (searchNumberKOrLess == - 1)
        {
            Console.WriteLine("There is no smaller number, then number K");
        }
        else
        {
            Console.WriteLine("Largest smaller number, then number K is {0}", arrnumberN[(searchNumberKOrLess * (-1) - 2)]);
        }
    }
}
